<template>
	<view class="index-content">
		<TopBar :indexflag="true" :combakflag="true" :lang="false" :bottom="true" :title="$t('ConfirmOrder')"
			:barstyle="colortopic()" Color="#fff"></TopBar>
		<view class="order-list">
			<view class="list" :style="{direction:i18nLocale=='ug'?'rtl':''}">
				<!-- <view class="">{{item.order.out_trade_no}}</view> -->
				<view class="time">
					<text>{{$t('TimePlaced')}}:</text>
					<view class="" style="direction: ltr;">{{orderdata.paid_at?orderdata.paid_at:orderdata.created_at}}
					</view>
					<u-icon name="checkmark-circle-fill" :color="colortopic()" size="25" v-if="orderdata.status!=1"></u-icon>
					<u-icon name="qzone-circle-fill" :color="colortopic()" size="25" v-if="orderdata.status==0"></u-icon>
				</view>
				<view class="totalprice-box">
					<text>{{$t('OrderType')}}</text>
					<text class="served" v-if="orderdata.status==0 || orderdata.status==null"
						@click.stop="changefinsh(orderdata.id,'status')">{{$t('Served')}}</text>
					<text class="order-type" v-if="orderdata.status==0">{{$t('New')}}</text>
					<text class="order-type" style="color:#999" v-if="orderdata.status!=0">{{$t('ServedYes')}}</text>
				</view>
				<view class="order-item">
					<view class="table-content">
						<view class="title">{{$t('TableNumber')}}</view>
						<view class="number">{{orderdata.table_number}}</view>
					</view>
					<view class="item" v-for="(subitem,sub_index) in orderdata.items">
						<view class="left">
							<view class="name">{{i18nLocale=='ug'?subitem.ug_name:subitem.cn_name}}</view>
						</view>
						<view class="right">
							<view class="number">X{{subitem.qty}}</view>
							<view class="price">￥{{subitem.price}}</view>
						</view>
					</view>
					<view class="totalprice-box">
						<text>{{$t('PlaceOrder')}}</text>
						<text style="color:#999" v-if="orderdata.employee">{{orderdata.employee[0].name}}</text>
						<text style="color:#999" v-else >{{$t('')}}</text>
					</view>
					<view class="totalprice-box">
						<text>{{$t('Remark')}}</text>
						<text style="color:#999">{{orderdata.remark}}</text>
					</view>
					<view class="totalprice-box">
						<text>{{$t('TotalPrice')}}</text>
						<text class="totalprice">￥{{orderdata.fee}}</text>
					</view>

					<view class="button" v-if="orderdata.payment_status==0"
						@click.stop="changefinsh(orderdata.id,'payment_status')">
						{{$t('Pay')}}
					</view>
				</view>

			</view>
			<Loading :show="loadshow" iconName="circle" bgZindex="99" bgColor="" :text="$t('Loading')"></Loading>
			<Loading :show="tabloadshow" bgZindex="99" iconName="circle-round" :showText="false"></Loading>
		</view>
		<u-popup :show="codepop" :round="10" mode="center" @close="codeClose" @open="codeOpen">
			<view class="pop-box">
				<view class="pop-title">{{$t('CodePay')}}</view>
				<Qrcode v-if="code_url" :url="code_url" class="code"></Qrcode>
				<view class="button-grop">
					<view class="button" @click="paybutton('paid')" style="background-color:#494FB6;">
						{{$t('OtherWays')}}
					</view>
					<view class="button" @click="paybutton('code')" :style="{backgroundColor:colortopic()}">
						{{$t('PayFinish')}}
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getorderone,
	} from '@/api/shop.js';
	export default {
		data() {
			return {
				orderdata: '',
				loadshow: false,
				codepop: false,
				code_url: '',
				order_id: '',
				logo: 'https://static.clewm.net/cli/images/cli_logo_new.png'

			}
		},
		computed: {
			i18nLocale() {
				return this.$i18n.locale;
			},
		},
		onLoad(e) {
			if (e.id) {
				this.getOrders(e.id)
			}
		},
		methods: {
			getOrders(id) {
				let that = this;
				this.loadshow = true;
				getorderone({
					id: id
				}).then((res) => {
					if (res.code == 200) {
						let data = res.body;
						that.loadshow = false
						that.orderdata = data.data;

					}
				})
			},
			codeOpen() {},
			codeClose() {
				this.codepop = false;
			},
			changefinsh(id, type) {
				let that = this;
				that.order_id = id;
				if (type == 'status') {
					orderstatus({
						id: id,
						status: 1,
					}).then((res) => {
						if (res.code == 200) {
							that.changeNav('no')
						}
					})
				} else if (type == 'payment_status') {
					that.code_url = 'http://restaurant.dikidiki.cn/pay?order_id=' + id;
					// canvas 生产图片
					that.$store.commit('Setqrcodeurl', that.code_url);
					that.codepop = true;
				}
			},
			//支付弹出
			paybutton(type) {
				let that = this;
				if (type == 'paid') {
					//现金付款
					orderstatus({
						id: that.order_id,
						status: 4,
						payment_status: 1,
						action: 'paid'
					}).then((res) => {
						if (res.code == 200) {
							that.changeNav('no');
						}
						that.codepop = false;
					})
				} else {
					that.codepop = false;
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.index-content {
		width: 100%;
		height: 100%;
		box-sizing: border-box;

		.topnav {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-around;
			background-color: $uni-bg-color-box;
			box-sizing: border-box;
			padding: 0rpx 20rpx;
			font-size: $uni-font-size-base;

			.item {
				width: 40%;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 20rpx 0rpx;
			}

			.acitem {
				color: $uni-color-topic;
			}
		}

		.order-list {
			width: 100%;
			height: calc(100% - 80rpx);
			box-sizing: border-box;
			padding: 0rpx 20rpx;

			.list {
				width: 100%;
				background: #FFFFFF;
				box-shadow: $uni-bg-shadow;
				border-radius: $uni-border-radius-lg;
				margin-top: 20rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 20rpx 40rpx;
				box-sizing: border-box;

				.time {
					width: 100%;
					padding: 10rpx 0rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28rpx;
					color: #000;

					text {
						color: #808080;
					}

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}

				.order-item {
					width: 100%;
					display: flex;
					flex-direction: column;
					position: relative;

					.item {
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 20rpx 0rpx;

						.left {
							display: flex;
							align-items: center;

							image {
								width: 120rpx;
								height: 120rpx;
								border-radius: 20rpx;
							}

							.name {
								color: $uni-color-title;
								font-size: $uni-font-size-base;
								// padding: 0rpx 30rpx;
							}
						}

						.right {
							display: flex;
							align-items: center;

							.price {
								color: $uni-color-topic;
								font-size: $uni-font-size-base;
								// padding: 0rpx 30rpx;
							}

							.number {
								color: $uni-text-color-grey;
								font-size: $uni-font-size-sm1;
								padding: 0rpx 30rpx;
							}

						}

					}
					.totalprice-box {
						display: flex;
						justify-content: space-between;
						align-items: center;
						font-size: $uni-font-size-base;
						margin-top: 10rpx;
						.totalprice {
							color: #f4464b;
							font-size: 32rpx;
						}

						.served {
							padding: 7rpx 10rpx;
							border-radius: 10rpx;
							background-color: $uni-color-topic2;
							color: #fff;
							font-size: $uni-font-size-base;
						}

						.order-type {
							// width: 100rpx;
							// height: 100rpx;
							// border-radius: 100%;
							padding: 10rpx;
							display: flex;
							justify-content: center;
							align-items: center;
							// background-color: $uni-color-topic;
							color: $uni-color-topic;
							font-size: $uni-font-size-lg;
						}
					}

					.table-content {
						width: 100%;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.title {
							font-size: $uni-font-size-base;
						}

						.number {
							width: 60rpx;
							height: 60rpx;
							border-radius: 100%;
							display: flex;
							justify-content: center;
							align-items: center;
							background-color: $uni-color-topic;
							color: #fff;
							font-size: $uni-font-size-lg;
						}
					}

					.button {
						background-color: $uni-color-topic;
						border-radius: $uni-border-radius-lg;
						padding: 20rpx 80rpx;
						margin: 0 auto;
						color: #fff;
					}

					.type-icon {
						position: absolute;
						top: 0%;
						left: 0%;
						transform: rotate(45deg);
						background-color: rgba(0, 0, 0, 0.4);
						color: $uni-color-topic;
						width: 100rpx;
						height: 100rpx;
						border-radius: 100%;
						display: flex;
						justify-content: center;
						align-items: center;
					}


				}

				.totalprice-box {
					width: 100%;
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: $uni-font-size-base;

					.totalprice {
						color: #f4464b;
						font-size: 32rpx;
					}

					.served {
						padding: 7rpx 10rpx;
						border-radius: 10rpx;
						background-color: $uni-color-topic2;
						color: #fff;
						font-size: $uni-font-size-base;
					}

					.order-type {
						// width: 100rpx;
						// height: 100rpx;
						// border-radius: 100%;
						padding: 10rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						// background-color: $uni-color-topic;
						color: $uni-color-topic;
						font-size: $uni-font-size-lg;
					}
				}


			}
		}
	}

	.pop-box {
		height: 630rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 50rpx 60rpx;

		.pop-title {
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 20rpx 0rpx;
		}

		.button-grop {
			width: 100%;
			display: flex;
			justify-content: space-around;
			margin-top: 80rpx;
			color: #fff;

			.button {
				border: 1rpx solid #999;
				padding: 10rpx 30rpx;
				border-radius: 20rpx;
				margin: 0rpx 20rpx;
			}
		}
	}
</style>